package logic

import (
	"context"
	"shopping/shoppingrpc/shoppingrpc"

	"shopping/shoppingapi/internal/svc"
	"shopping/shoppingapi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductListLogic {
	return &ProductListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProductListLogic) ProductList(req *types.ProductListRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	list, err := l.svcCtx.ShoppingRpc.ProductsList(l.ctx, &shoppingrpc.ProductsListRequest{
		Page: req.Page,
		Size: req.Size,
		Name: req.Name,
	})
	if err != nil {
		return &types.Response{
			Message: "列表展示失败",
			Code:    "500",
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "列表展示成功",
		Code:    "200",
		Data:    list,
	}, nil
}
